package com.kobeliu.api.config;

import io.lettuce.core.support.ConnectionPoolSupport;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonConfig {

    @Bean(destroyMethod = "shutdown")
    public RedissonClient redissonClient(){

        Config config = new Config();
        config.useSingleServer()
                //线上
                .setAddress("redis://192.168.6.83:6379")
                //本地
//                .setAddress("redis://192.168.10.70:6379")
                .setPassword("root")
                .setDatabase(0)
                .setConnectionMinimumIdleSize(20) //设置最小空闲连接数
                .setConnectionPoolSize(25) //连接池最大连接数
                .setIdleConnectionTimeout(60*1000) //销毁超时时间
                .setConnectTimeout(15*1000) //客户端获得redis连接的超时时间
                .setTimeout(15*1000)       //响应的超时时间
                .setPingConnectionInterval(0); //不发送ping命令

        return Redisson.create(config);
    }
}
